﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SGRapidForm.Permission.Service.Interface;
using SGRapidForm.Common;
using SGRapidForm.Permission.Entity;

namespace SGDemo.Web
{
    public partial class HelpItem : System.Web.UI.Page
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");
        protected void Page_Load(object sender, EventArgs e)
        {
            JSManager.RegAjax(Header, this.GetType().BaseType);
            if (!this.IsPostBack)
            {
                rptHelpCategory.DataSource = _permissionService.HelpCategory_GetAll();
                rptHelpCategory.DataBind();
               
                if (!string.IsNullOrEmpty(this.Request.QueryString["Keyid"]))
                {
                    SGRapidForm.Permission.Entity.Help help = _permissionService.Help_GetByKeyid(this.Request.QueryString["Keyid"]);
                    ltlTitle.Text = help.Title;
                    ltlBody.Text = help.Body;
                    BindLableMethod(this.Request.QueryString["CategoryKeyid"]);
                }
            }

          
        }

        protected void BindLableMethod(string keyid)
        {
             

              if (keyid != "" || keyid != null)
              {
                  List<HelpCategory> helpcategoryCell = _permissionService.HelpCategory_GetCategoryAll().Where(n => n.Keyid == keyid).ToList();
                  foreach (HelpCategory helpcategorys in helpcategoryCell)
                  {
                      foreach (HelpCategory helcategory in _permissionService.HelpCategory_GetCategoryAll().Where(n => n.Keyid == helpcategorys.ParentKeyid))
                      {
                          catogoryNameID.Text = helcategory.HelpCategoryName;

                      }

                      categoryNameChildID.Text = helpcategorys.HelpCategoryName;
                  }


              }
        }


        //绑定类别下的子节点
        protected List<HelpCategory> GetHelpByCatogoryKeyid(string parentkeyid)
        {

            return _permissionService.HelpCategory_GetByParentKeyid(parentkeyid);
        }
    }


}